package com.app.mymusic.widget;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.app.mymusic.R;
import com.app.mymusic.model.Mp3Info;
import com.app.mymusic.ui.SingerInfoActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/8/11.
 */
public class PopWindowMenu {

    @BindView(R.id.popmenu_title_tv)
    TextView popmenuTitleTv;
    @BindView(R.id.popmenu_play_btn)
    Button popmenuPlayBtn;
    @BindView(R.id.popmenu_add_btn)
    Button popmenuAddBtn;
    @BindView(R.id.popmenu_singger_btn)
    Button popmenuSinggerBtn;
    @BindView(R.id.popmenu_album_btn)
    Button popmenuAlbumBtn;
    @BindView(R.id.popmenu_cancle_btn)
    Button popmenuCancleBtn;

    private Mp3Info mp3Info;
    private PopupWindow pw;
    private Context context;

    public PopWindowMenu( Mp3Info mp3Info) {
        this.mp3Info=mp3Info;


    }

    public PopupWindow getPopWindow(Context context) {
        this.context=context;
        View view = LayoutInflater.from(context).inflate(R.layout.popwindow_menu, null);
        ButterKnife.bind(this, view);
        pw = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        pw.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.pop_background));
        popmenuTitleTv.setText(mp3Info.getTitle()+"--"+mp3Info.getArtist());
        return pw;
    }

    @OnClick({R.id.popmenu_play_btn, R.id.popmenu_add_btn, R.id.popmenu_singger_btn, R.id.popmenu_album_btn, R.id.popmenu_cancle_btn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.popmenu_play_btn:
                break;
            case R.id.popmenu_add_btn:
                break;
            case R.id.popmenu_singger_btn:
                Intent i=new Intent();
                i.putExtra("artist",mp3Info.getArtist());
                i.setClass(context, SingerInfoActivity.class);
                context.startActivity(i);
                break;
            case R.id.popmenu_album_btn:
                break;
            case R.id.popmenu_cancle_btn:
               if(pw!=null)
               {
                   pw.dismiss();
               }
                break;
        }
    }
}
